package com.xy.inversion.improve;

/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/6/7 19:09
 * @description 依赖倒置 优化面向接口编程
 */
public class DependenceInversion {
    public static void main(String[] args) {

        // 客户端无需改变
        Person person = new Person();
        person.receive(new Email());
        person.receive(new WeiXin());
    }
}

/**
 * 接口
 */
interface Receiver {
    Object getInfo();
}

/**
 * 电子邮箱实现类
 */
class Email implements Receiver {
    @Override
    public String getInfo() {
        return "电子邮件信息: hello world";
    }
}

/**
 * 微信消息实现类
 */
class WeiXin implements Receiver {
    @Override
    public String getInfo() {
        return "微信信息: hello world";
    }
}


class Person {
    public void receive(Receiver receiver) {
        System.out.println(receiver.getInfo());
    }
}